package com.shop.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shop.entity.Info;
import com.shop.entity.Res;
import com.shop.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-03-04
 */
@RestController
@RequestMapping("/info")
public class InfoController {

    @Autowired
    InfoService infoService;

    @GetMapping("getChildren")
    public Res getFirstInfo (String  pid) {
        QueryWrapper<Info> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pid",pid);
        List<Info> list = infoService.list(queryWrapper);
        return Res.success(list);
    }
    @PostMapping("add")
    public Res add(@RequestBody HashMap<String,String> params) {
        String parentId = params.get("parentId");
        String msg = params.get("msg");
        Info info = new Info();
        info.setId(UUID.randomUUID().toString());
        info.setPid(parentId);
        info.setMsg(msg);
        boolean save = infoService.save(info);
        return save?Res.success():Res.error();
    }

}

